package pl.edu.agh.mobsys.activities.soapactivities;

import java.util.ArrayList;

import pl.edu.agh.mobsys.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class OLDAddJob extends Activity implements View.OnClickListener, DialogInterface.OnClickListener, OnKeyListener {
	
	EditText jobName;
	EditText jobCommand;
	EditText jobArguments;
	Button btnAdd;
	
	/*String[] info = {"what", "where", "why"};
	String currentMenu;*/
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_job);
		
		jobName = (EditText)findViewById(R.id.jobName);
		jobCommand = (EditText)findViewById(R.id.jobCommand);
		jobArguments = (EditText)findViewById(R.id.jobArguments);
		//btnAdd = (Button)findViewById(R.id.btnAdd);
	
		btnAdd.setOnClickListener(this);
		jobName.setOnKeyListener(this);
	}
	
	/*public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		MenuItem item;
		item = menu.add("delete");
		item.setIcon(R.drawable.bunny);
		item = menu.add("info");
		item.setIcon(R.drawable.info);
		item = menu.add("star");
		item.setIcon(R.drawable.star);
		return true;
	}
	
	public boolean onOptionsItemSelected(MenuItem item) {
		super.onOptionsItemSelected(item);
		if(item.hasSubMenu()==false) {
			if(item.getTitle() == "info") {
				currentMenu = "info";
				this.displayPopup("info items", this.info);
			}
			if(item.getTitle() == "delete") {
				int index = listItems.getSelectedItemPosition();
				this.deleteItem(index);
			}
		}
		return true;
	}*/
	
	private void addItem(String jName, String jCommand, String jArguments) {
		if(jName!="") {
			
			//System.out.println(item + " added");
			//this.toDoItems.add(item);
			//this.aa.notifyDataSetChanged();
			this.jobName.setText("");
			//Toast.makeText(getApplicationContext(), item + " added", Toast.LENGTH_LONG).show();
		}
	}
	
	private void deleteItem(int itemId) {
		if(itemId >= 0) {
			//String itemName = (String)listItems.getItemAtPosition(itemId);
			//Toast.makeText(getApplicationContext(), itemName + " deleted", Toast.LENGTH_LONG).show();
			//this.toDoItems.remove(itemId);
			//aa.notifyDataSetChanged();
		}		
	}

	private void displayPopup(String title, String[] items) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setTitle(title);
		builder.setItems(items, this);
		builder.show();
	}
	
	public void onClick(View v) {
		if(v==this.btnAdd) {
			//this.addItem(this.jobName.getText().toString());
		}
	}

	public boolean onKey(View v, int keyCode, KeyEvent event) {
		if(event.getAction()==KeyEvent.ACTION_DOWN && keyCode==KeyEvent.KEYCODE_DPAD_CENTER) {
			//this.addItem(this.jobName.getText().toString());
		}
		return false;
	}

	public void onClick(DialogInterface dialog, int item) {
		
		
	}
}